{% extends 'base.html' %}
{% load static %}
{% load user_tags %}
{% block css %}

{% endblock %}
{% block title %}
    任务列表
{% endblock %}
{% block page-title %}
    任务列表
{% endblock %}
{% block page-content %}
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">查看任务列表</h3>
                </div>
                <div class="panel-body">
                    {% if messages %}
                        {% for message in messages %}
                            <div class="alert alert-{{ message.tags }} alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                {{ message }}
                            </div>
                        {% endfor %}
                    {% endif %}
                    <div class="row" style="margin-bottom: 5px">
                        <div class="col-md-2" style="float: right">
                            <form class="form-horizontal" role="form">
                                    <div class="input-group">
                                        <input type="text" id="keyword" name="keyword" class="form-control"  value="{{ keyword|default_if_none:'' }}" placeholder="关键字">
                                        <span class="input-group-btn">
                                        <button type="submit" class="btn btn-effect-ripple btn-primary">搜索</button>
                                        </span>
                                    </div>

                            </form>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12 col-sm-12 col-xs-12">
                            <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th>任务名称</th>
                            <th>上线主机</th>
                            <th>提交人</th>
                            <th>提交时间</th>
                            <th>审核人</th>
                            <th>审核时间</th>
                            <th>状态</th>
                            <th>动作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for task in object_list %}
                            <tr>
                                <td>{{ task.task.name }}</td>
                                <td>{{ task.dest_hosts.all|get_host_names2 }}</td>
                                <td>{{ task.apply_user }}</td>
                                <td>{{ task.created_at }}</td>
                                <td>{{ task.reviewer|default_if_none:'暂无' }}</td>
                                <td>{{ task.review_at|default_if_none:'暂无' }}</td>
                                <td><label class="label {% if task.status == 0 %}label-warning{% elif task.status == 2%}label-info{% endif %}">{{ task.get_status_display }}</label></td>
                                <td>
                                    <a href="{% url 'task:task_detail' task.id %}?prev=tasks">
                                        {% if task.status == 0 %}
                                            {% if task.apply_user == user %}查看
                                            {% elif task.apply_user != user and perms.tasks.review_task %}审核
                                            {% endif %}
                                            {% elif task.status == 2 %}
                                            {% if task.apply_user == user %}发布
                                                {% elif perms.tasks.review_task %}查看
                                                {% endif %}
                                        {% endif %}</a>
                                </td>

                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-4">
                           <p style="margin-top: 10px"> 显示 [{{ page_obj.paginator.count }}] 条数据中的 第 [{{ page_obj.start_index }}] 至 [{{ page_obj.end_index }}] 的数据</p>
                        </div>
                        <div class="col-md-8">
                             {% if page_obj.paginator.num_pages > 1 %}
                                {% include '_paginator.html' %}
                             {% endif %}
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
{% endblock %}
{% block js %}
    <script>
        $('.task').addClass('active');
        $('.task .tasks').addClass('active');
    </script>
{% endblock %}
